package practice.sort;

/**
 * 选择排序
 */
public class SelectionSort extends SortAdaptor{

    public static void main(String[] args) {
        int[] nums = {3,9,10,2,3,123,239,4,13,443,23,29};
        sort(nums);
        for (int num :
                nums) {
            System.out.print(num + " ");
        }
    }

    public static void sort(int[] nums) {
        if (nums.length <= 0) {
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            int minIndex = i;
            for (int j = i; j < nums.length; j++) {
                if (nums[j] < nums[minIndex]) {
                    minIndex = j;
                }
            }
            swap(nums, i, minIndex);
        }
    }
}
